<html lang="en">
<head>
    <title>已发布游记管理</title>
    <#include "../common/header.ftl">
    <script>
        $(function () {
            /*$(".changeBtn").click(function () {
                var id = $(this).data("id");
                var state = $(this).data("state");
                $.get("/travel/changeState.do",{id:id,state:state},function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示","修改成功");
                        window.location.reload();
                    }else{
                        $.messager.confirm("温馨提示",data.msg);
                    }
                });
            });*/
            var travelId;
            $(".changeBtn").click(function () {

                var json = $(this).data("json");
                travelId = json.travelId;
                if (json){
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='travel.id']").val(json.travelId);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='subTitle']").val(json.subTitle);
                    $("#editForm img").attr("src",json.coverUrl);
                    $("#editForm input[name='schedule']").val(json.schedule);
                    $("#editForm select[name='type']").val(json.type);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);

                }
                $("#showModal").modal("show");
            });
            $(".submitBtn").click(function(){
                $("#editForm").ajaxSubmit({
                beforeSubmit:function (params, form, options) {
                    var value = $("#editForm select[name='type']").val();
                    if (value==-1){
                        $.messager.confirm("温馨提示","请选择推荐类型");
                        return false;
                    }
                },
                success:function (data) {
                    if (data.success) {
                        window.location.reload();
                    }
                }
            });

            });

            $("#img").change(function () {
               var url = window.URL.createObjectURL(this.files[0]);
                $("#editForm img").attr("src",url);
            });

            $("#skip").click(function () {

                //获取查看的游记的信息,传送id过去
                $.get("/travel/selectByTravelId.do?travelId=" + travelId,function (data) {

                    $("#editModal .modal-body").html(data.travelContent.content);
                });
                $("#editModal").modal("show");

            });

            //取消推荐
            $(".delete").click(function () {
                var commendId = $(this).data("commendid");
                $.get("/travelCommend/delete.do",{commendId:commendId},function (data) {
                    if (data.success) {
                        window.location.reload();
                    } else {
                        $.messager.confirm("温馨提示", "操作错误")
                    }
                });
            });
        });
    </script>
    <style>
        /*设置模态框中的图片铺满*/
        #editModal img{
            width: 100%;
        }
        /*当内容大于模态框时,会自定设置滚动条*/
        #editModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>

</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="travelCommend">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                           placeholder="请输入昵称/标题">
                </div>
                <div class="form-group">
                    <label  class="col-sm-6 control-label">推荐类型:</label>
                    <div class="col-sm-6">
                        <select class="form-control" id="type" name="type">
                            <option value="-1">全部</option>
                            <option value="0">周推荐</option>
                            <option value="1">月推荐</option>
                            <option value="2">攻略推荐</option>
                        </select>
                        <script>
                            $("#type").val(${qo.type});
                        </script>
                    </div>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>封面</th>
                        <th>标题</th>
                        <th>副标题</th>
                        <th>推荐时间</th>
                        <th>推荐类型</th>
                        <th> 操作</th>
                    </tr>
                </thead>
               <#list result.list as entity>
                   <tr>
                       <td>${entity_index + 1}</td>
                       <td><img src="${entity.coverUrl!}" width="40px"></td>
                       <td>${(entity.travel.title)!}</td>
                       <td>${(entity.subTitle)!}</td>
                       <td>${(entity.schedule?string("yyyy-MM-dd"))!}</td>
                       <td>${(entity.typeDisplay)!}</td>
                       <td>
                           <a href="javascript:void(0);" class="btn changeBtn" data-json='${entity.jsonString}'>修改</a>
                           <a href="javascript:void(0);" class="btn delete" data-commendid='${entity.id}'>取消推荐</a>
                       </td>
                   </tr>
               </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<!---部门编辑--->
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">游记推荐编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <input type="hidden" value="" name="travel.id" id="travelId">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="title" value="">
                            <input type="hidden" class="form-control" name="parent.id" value="" placeholder="请输入推荐标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="subTitle" value="" placeholder="请输入副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="" alt="封面" width="200px;">
                            <input id="img" type="file" name="file">
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="schedule" value="" readonly onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="type" name="type">
                                <option value="-1">全部</option>
                                <option value="0">周推荐</option>
                                <option value="1">月推荐</option>
                                <option value="2">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a href="javascript:void(0)" target="_blank" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
<!---部门编辑--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>